home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
boss
/
boss_sup.lzh
/
WN_PDOWN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-05
|
14KB
|
394 lines
/*
** WN_PDOWN - Pulldown Menu/Window Functions
**
** Adapted, with permission, from Keith Funk's code.
**
** Copyright (C) 1992 - Philip A. Mongelluzzo
** All rights reserved.
**
*/
#include "winboss.h" /* window header */
#define ITEM scrn[i] /* some short hand */
/*
*************
* wn_pdopen *
*************
*/
/*
** wn_pdopen(page,row,col,width,height,watr,batr,hkatr,mx,aflag)
*/
wn_pdopen(page,row,col,width,height,watr,batr,hkatr,mx,aflag)
int page; /* video page */
int row, col; /* window - upper row/col */
int width, height; /* window - height & width */
WNPDPTR mx; /* pointer to pulldown menu struct */
int aflag; /* active menu items flag */
int watr, batr; /* attributes - window & border */
int hkatr; /* hot key attribute */
{
int i, ix; /* scratch integers */
WINDOWPTR w; /* window pointer */
if(!mx->winopn) { /* menu not open, open it now */
mx->lndx = -1; /* set index out of range */
w = wn_open(page, row, col, width, height, watr, batr);
if (w == NULL) return(FALSE); /* out of mem or just fubar */
wn_sync(w,FALSE); /* sync cursor */
mx->wpsave = w; /* save pointer */
mx->wa = watr; /* window atrib */
mx->ba = batr; /* border atrib */
mx->hka = hkatr; /* hot key atrib */
mx->winopn = TRUE; /* say window is open */
}
else {
w = mx->wpsave; /* fetch window pointer */
watr = mx->wa; /* fetch window atrib */
hkatr = mx->hka; /* fetch hot key atrib */
}
/*
** For as long as there is data, display it.
** Use the first active menu item as the initial index.
** If the item is active then highlight the hot key and remember it.
** ONLY IF MENU IS ACTIVE
*/
i = 0; /* init index */
while(mx->ITEM.r != 99) {
wn_putsa(w, mx->ITEM.r, mx->ITEM.c, mx->ITEM.t, watr);
if(aflag) {
if(mx->ITEM.status == PDACTIVE) {
if(mx->lndx == -1) mx->lndx = i;
ix = wn_cndx(mx->ITEM.t, mx->ITEM.hkc,0);
wn_putca(w, mx->ITEM.r, mx->ITEM.c+ix, mx->ITEM.hkc, mx->hka);
}
}
i++;
}
return(TRUE);
}
/*
**************
* wn_pdclose *
**************
*/
void wn_pdclose(mx) /* close pulldown */
WNPDPTR mx;
{
if(!mx->winopn) return; /* dont be stupid */
wn_close(mx->wpsave);
mx->winopn = FALSE;
}
/*
***************
* wn_pdupdate *
***************
*/
int wn_pdupdate(mx, i, style) /* update menu item display */
WNPDPTR mx; /* pull down menu struct ptr */
int i; /* menu item to update */
int style; /* PDNORMAL or PDREVERSE */
{
int watr; /* window contents attribute */
int hkatr; /* attributes for hotkey */
int atr; /* atrib that will be used */
int hklite; /* hotkey highlight attrib */
WINDOWPTR w; /* window pointer */
int ix; /* hot key char index */
if (!mx->winopn) return(FALSE); /* window isn't open */
w = mx->wpsave; /* fetch window ptr */
watr = mx->wa; /* and misc atributes */
hkatr = mx->hka; /* .... */
if (style == PDREVERSE) /* use reverse video */
{
atr = v_setrev(watr); /* make reverse atrib for line */
hklite = ((hkatr & 0x0F) | (~watr & 0x70)); /* form new hotkey atrib */
}
else /* normal video */
{
atr = watr; /* right from the structure */
hklite = hkatr; /* as it was opened */
}
wn_putsa(w, mx->ITEM.r, mx->ITEM.c, mx->ITEM.t, atr);
if (mx->ITEM.status == PDACTIVE) { /* display hot key */
ix = wn_cndx(mx->ITEM.t, mx->ITEM.hkc,0);
wn_putca(w, mx->ITEM.r, mx->ITEM.c + ix, mx->ITEM.hkc, hklite);
}
return(TRUE);
}
#ifdef COMMENTS
/*
***************
* wn_pdsettog * /* set toggle */
***************
*/
#endif
wn_pdsettog(mx, i) /* reverse state of togle */
WNPDPTR mx; /* menu pointer */
int i; /* menu item of interest */
{
int j, k; /* scratch intergers */
if((mx->ITEM.type != 'T') && (mx->ITEM.type != 'E'))
return(PDTOGOK); /* no toggles active */
if (*(mx->ITEM.t) == '√') /* toggle is ON, so turn it OFF. */
{
*(mx->ITEM.t) = ' '; /* by loading a blank */
return(PDTOGOK); /* then return */
}
*(mx->ITEM.t) = '√'; /* toggle is off so turn it on */
if(mx->ITEM.type == 'T') /* exclusive toggle ?? */
return(PDTOGOK); /* no... simply return */
k = -2; /* set index mark */
for (j = mx->fm; j <= mx->lm; j++) { /* turn all other toggles OFF */
if ((j != i) && (mx->scrn[j].type != 'S')) {
if (*(mx->scrn[j].t) == '√') { /* was ON, so save its index */
k = j;
*(mx->scrn[j].t) = ' ';
}
}
}
if(k == -2) /* no other toggles were on */
return(PDTOGOK); /* so say all went well */
else
return(k); /* ret index of previous ON toggle */
}
/*
***************
* wn_pdgettog *
***************
*/
wn_pdgettog(mx, i) /* get toggle */
WNPDPTR mx; /* menu pointer */
int i; /* RETURN val of menu item of interest */
{ /* -1 sez look for any ON toggle */
int j; /* scratch integer */
if (i != -1) /* get status of specific toggle */
{
for (j = mx->fm; j <= mx->lm; j++) /* find the toggle by its return code */
if (mx->scrn[j].rv == i) break;
if (*(mx->scrn[j].t) == '√') /* ALT-251, toggle is ON */
return(TRUE);
else
return(FALSE);
}
else /* find out if any toggle is ON */
{
for (j = mx->fm; j <= mx->lm; j++)
if (*(mx->scrn[j].t) == '√') /* ALT-251, toggle is ON */
return(mx->scrn[j].rv); /* return toggles rv code */
}
return(PDTOGOK); /* no toggles are ON */
}
/*
***************
* wn_pdactive *
***************
*/
void wn_pdactive(mx, i, action) /* menu activate/deactivate */
WNPDPTR mx; /* pointer to menu structure. */
int i; /* menu item's RETURN code */
int action; /* TRUE=activate, FALSE=de-activate */
{
int j; /* scratch integer */
for (j = mx->fm; j <= mx->lm; j++) /* look up item via RETURN code */
if (mx->scrn[j].rv == i) break;
if(action == TRUE)
mx->scrn[j].status = PDACTIVE;
else
mx->scrn[j].status = PDINACTIVE;
}
/*
*************
* wn_pdtype *
*************
*/
int wn_pdtype(mx, i, newtype, action)
WNPDPTR mx; /* pointer to menu structure. */
int i; /* menu item RETURN code */
char newtype; /* ignored if Action is FALSE */
int action; /* TRU